home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frn7_4_6
- Caption = "Metropolitan Statistics"
- ClientHeight = 1890
- ClientLeft = 915
- ClientTop = 1980
- ClientWidth = 6855
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 1890
- ScaleWidth = 6855
- Begin VB.PictureBox picResult
- Height = 1215
- Left = 120
- ScaleHeight = 1155
- ScaleWidth = 6555
- TabIndex = 3
- Top = 600
- Width = 6612
- End
- Begin VB.CommandButton cmdDisplayStats
- Caption = "Display City Stats"
- Default = -1 'True
- Height = 375
- Left = 4200
- TabIndex = 2
- Top = 120
- Width = 1815
- End
- Begin VB.TextBox txtCity
- Height = 285
- Left = 2160
- TabIndex = 1
- Top = 240
- Width = 1335
- End
- Begin VB.Label lblName
- Caption = "Name of city:"
- Height = 255
- Left = 960
- TabIndex = 0
- Top = 240
- Width = 1215
- End
- Attribute VB_Name = "frn7_4_6"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim city(1 To 10) As String, pop(1 To 10) As Single, income(1 To 10) As Single
- Dim natives(1 To 10) As Single, advDeg(1 To 10) As Single
- Private Sub cmdDisplayStats_Click()
- Dim searchCity As String, result As Integer
- 'Search for city in the metropolitan areas table
- Call GetCityName(searchCity)
- Call FindCity(searchCity, result)
- picResult.Cls
- If result > 0 Then
- Call ShowData(result)
- Else
- picResult.Print searchCity & " not in file"
- End If
- End Sub
- Private Sub FindCity(searchCity As String, result As Integer)
- Dim first As Integer, middle As Integer, last As Integer
- Dim foundFlag As Boolean
- 'Binary search table for city name
- first = 1
- last = 10
- foundFlag = False
- Do While (first <= last) And (foundFlag = False)
- middle = Int((first + last) / 2)
- Select Case UCase(city(middle))
- Case searchCity
- foundFlag = True
- Case Is > searchCity
- last = middle - 1
- Case Is < searchCity
- first = middle + 1
- End Select
- Loop
- If foundFlag Then
- result = middle
- Else
- result = 0
- End If
- End Sub
- Private Sub Form_Load()
- Dim j As Integer
- 'Assume that the data for city name, population, medium income, % native,
- 'and % advanced degree have been placed in the file "CITYSTAT.TXT"
- '(First line of file is "Boston", 4.2, 4066, 73, 12)
- Open App.Path & "\CITYSTAT.TXT" For Input As #1
- For j = 1 To 10
- Input #1, city(j), pop(j), income(j), natives(j), advDeg(j)
- Next j
- Close #1
- End Sub
- Private Sub GetCityName(searchCity As String)
- 'Request name of city as input
- searchCity = UCase(Trim(txtCity.Text))
- End Sub
- Private Sub ShowData(index As Integer)
- 'Display city and associated information
- picResult.Print , "Pop. in", "Med. income", "% Native", "% Advanced"
- picResult.Print "Metro Area", "millions", "per hsd", "to State", "Degree"
- picResult.Print
- picResult.Print city(index); Tab(16); pop(index), income(index),
- picResult.Print natives(index), advDeg(index)
- End Sub
-